package com.wsd.smartcarwasher.controller;

import com.wsd.smartcarwasher.domain.Problem;
import com.wsd.smartcarwasher.service.ProblemService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Api(tags = {"帮助中心"})
@Controller
@CrossOrigin
public class HeplController {

    @Resource
    private ProblemService problemService;
    @ApiOperation(
            value = "小程序－获取常见问题解释说明 ",
            notes = "小程序－获取常见问题解释说明",
            produces = "application/json",
            response = Problem.class
    )

    @RequestMapping(
            value = {"/v1/probelm"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getProblem() {
        return  ReturnUtil.Success("获取常见问题说明成功",this.problemService.getProblem());
    }



    @ApiOperation(
            value = "PC端－获取帮助内容说明 ",
            notes = "PC端－获取帮助内容",
            produces = "application/json",
            response = Problem.class
    )

    @RequestMapping(
            value = {"/v1/help/getAll"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getAll() {
        return  ReturnUtil.Success("获取常见问题说明成功",this.problemService.getAll());
    }



    @ApiOperation(
            value = "PC端－新增帮助内容 ",
            notes = "PC端－获取常见问题解释说明",
            produces = "application/json",
            response = Problem.class
    )

    @RequestMapping(
            value = {"/v1/help/add"},
            method = {RequestMethod.POST},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap add(@RequestBody Problem problem) {
        problem.setTime(new Date());
        int rows = this.problemService.insert(problem);
        if(rows >0){
            return ReturnUtil.Success("添加成功");
        }

        return  ReturnUtil.Error("添加失败");
    }


    @ApiOperation(
            value = "PC端－修改帮助内容 ",
            notes = "PC端－修改常见问题解释说明",
            produces = "application/json",
            response = Problem.class
    )

    @RequestMapping(
            value = {"/v1/help/update"},
            method = {RequestMethod.POST},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap update(@RequestBody Problem problem) {
        int rows = this.problemService.update(problem);
        if(rows >0){
            return ReturnUtil.Success("修改成功");
        }

        return  ReturnUtil.Error("修改失败");
    }


    @ApiOperation(
            value = "PC端－修改帮助内容 ",
            notes = "PC端－修改常见问题解释说明",
            produces = "application/json",
            response = Problem.class
    )

    @RequestMapping(
            value = {"/v1/help/delete"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap delete(@RequestParam Integer id) {
        int rows = this.problemService.delete(id);
        if(rows >0){
            return ReturnUtil.Success("删除成功");
        }

        return  ReturnUtil.Error("删除失败");
    }


}
